------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_12
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/06_prepare_individual.log
  log type:  text
 opened on:  19 Sep 2022, 11:38:44

. *This code re-codes the 2016 referndum data and prepares the analysis
. *The data is merged with the 2013 RCS pre/post data: 1=pre 2013; 2=post 2013; 3=pre 2016; 4=post 2016
. /*
> Procedure: 
> The data comes in wide format. Thus:
> 1) We code the pre-treatment covariates for all respondents 
> 2) We keep only the pre-treatment covariates and the DVs 
> 3) We re-shape the file into long format dropping pre-treatment covariates into single variables, 
> while all DVs remain 2 variables (pre post). 
> 4) We can then subtract pre post Dvs such that we can estimate the change in DiD designs. 
> */
. 
. * directory definitions 
. 
.         project, doinfo
project PlaceBased_analysis > Project Name: PlaceBased_analysis
project PlaceBased_analysis > Project Dir.: /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication
project PlaceBased_analysis > Build start : 19sep2022, 11:38:37
project PlaceBased_analysis > Do-file Name: 06_prepare_individual.do
project PlaceBased_analysis > Enclosing do-files:
project PlaceBased_analysis >     PlaceBased_analysis.do

.         global pdir "`r(pdir)'"                                                 // the project's main dir.

.         global dofile "`r(dofile)'"                                             // do-file's stub name

.         global data_original = "$pdir/data_original"  //data directory for coded data 

.         global data_coded = "$pdir/data_coded"  //data directory for coded data 

.         global figures = "$pdir/results/figures"  //data directory for figures

.         global tables = "$pdir/results/tables"  //data directory for tables

. 
.         project, uses("$data_coded/placebased_regional.dta")
project PlaceBased_analysis > do-file uses: "data_coded/placebased_regional.dta" filesig(1029121884:16892740)

.         project, original("$data_original/comune info/handcoded_brigdefile_comuneIDs.dta")
project PlaceBased_analysis > do-file uses original: "data_original/comune info/handcoded_brigdefile_comuneIDs.dta" filesig(27731806
> 69:1103515)

. 
. *
.         // read RCS 2013 file:
.         project, original("$data_original/election studies/ITA2013_RCSitvers2014_11_11/ITA2013_RCS(itvers2014_11_11).dta")
project PlaceBased_analysis > do-file uses original: "data_original/election studies/ITA2013_RCSitvers2014_11_11/ITA2013_RCS(itvers2
> 014_11_11).dta" filesig(3894127418:23716642)

.         use "$data_original/election studies/ITA2013_RCSitvers2014_11_11/ITA2013_RCS(itvers2014_11_11).dta", clear 
(Written by R.              )

. 
.         ** code variables we need:
.         gen female_1=0

.         replace female_1=1 if Q002==2 
(4,463 real changes made)

. 
.         decode Q004, gen(h1)

.         destring h1, replace  
h1: all characters numeric; replaced as int

.         gen age_1=2013-h1

.         drop h1

. 
.         gen unemployed_1=0

.         replace unemployed_1=1 if profes19==4
(870 real changes made)

. 
.         gen class_1=classe if classe<=4
(437 missing values generated)

. 
.         gen edu_1=titstu if titstu<=4
(1 missing value generated)

. 
.         gen eco_general_1=Q010 if Q010<=5
(52 missing values generated)

.         label values eco_general_1 Q010

.         revrs eco_general_1, replace 

. 
.         gen vote13_1=Q150
(1,991 missing values generated)

.         label values vote13_1 Q150

. 
.         gen polinterest_1=Q020

.         replace polinterest_1=. if polinterest_1>=5
(127 real changes made, 127 to missing)

.         label values polinterest_1 Q020

.         revrs polinterest_1, replace

. 
.         gen talk_politics_1=Q021

.         replace talk_politics_1=. if Q021>=7
(232 real changes made, 232 to missing)

.         label values talk_politics_1 Q021

. 
.         gen internal_efficacy_1=Q030_01 if Q030_01<=4
(224 missing values generated)

.         label values internal_efficacy_1 Q030_01

.         revrs internal_efficacy_1, replace

. 
.         gen pol_complex_1=Q030_02 if Q030_02<=4
(198 missing values generated)

.         label values pol_complex_1 Q030_02

.         revrs pol_complex_1, replace

. 
.         gen lr_1=Q032_01

.         replace lr_1=. if lr_1>=11
(1,762 real changes made, 1,762 to missing)

. 
.         gen lr_no_1=0 

.         replace lr_no_1=1 if Q032_01==11
(1,553 real changes made)

. 
.         ** save a temporary file to merge later as a cross-section for pre-treatment infos:
.         tempfile 13_pre

.         save `13_pre'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000004 saved as .dta format

. 
.         ** minimalize data:
.         keep ID eco_general_1 polinterest_1 talk_politics_1 vote13_1

. 
.         ** save a temporary file to merge later to integrate into panel:
.         tempfile 13itans

.         save `13itans'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000005 saved as .dta format

. 
. 
. 
. 
. *
.         // read referendum  file:
.         project, original("$data_original/election studies/ITANES_PRE-POST_Referendum_2016/ITANES_POSTREFERENDUM_2016_COS_COMPETIT
> ION.dta")
project PlaceBased_analysis > do-file uses original: "data_original/election studies/ITANES_PRE-POST_Referendum_2016/ITANES_POSTREFE
> RENDUM_2016_COS_COMPETITION.dta" filesig(1224006615:3599888)

.         use "$data_original/election studies/ITANES_PRE-POST_Referendum_2016/ITANES_POSTREFERENDUM_2016_COS_COMPETITION.dta", clea
> r

. 
.         *recode of pre-treatment variables. We only use pre-treatment covariates in the final design:  
. 
.         gen region_1=s04
(23 missing values generated)

.         label values region_1 s04

. 
.         gen province_1=s06
(323 missing values generated)

.         label values province_1 s06

.         bysort region_1: carryforward province_1, replace
province_1:  (299 real changes made)

. 
.         gen comune_1=s07

.         encode comune_1, gen(comune_id_1)

. 
.         *to merge with Istata IDs we need to clean the messy municipality IDs: 
.         replace comune_1="AlmÃ¨" if comune_1=="AlmÃÆÃÂš"
(1 real change made)

.         replace comune_1="Bolzano/Bozen" if comune_1=="Bolzano"
(3 real changes made)

.         replace comune_1="CanicattÃ¬" if comune_1=="CanicattÃÆÃÂ¬"
(1 real change made)

.         replace comune_1="CantÃ¹" if comune_1=="CantÃÆÃÂ¹"
(3 real changes made)

.         replace comune_1="Castelfranco Castelfranco Piandiscò" if comune_1=="Castelfranco di Sopra"
variable comune_1 was str29 now str36
(1 real change made)

.         replace comune_1="CittÃ  della Pieve" if comune_1=="Citta della Pieve"
(1 real change made)

.         replace comune_1="Sant’Angelo in Lizzola" if comune_1=="Colbordolo"
(1 real change made)

.         replace comune_1="ForlÃ¬" if comune_1=="ForlÃÆÃÂ¬"
(8 real changes made)

.         replace comune_1="GambolÃ²" if comune_1=="GambolÃÆÃÂ²"
(2 real changes made)

.         replace comune_1="Laives/Leifers" if comune_1=="Laives"
(1 real change made)

.         replace comune_1="MondovÃ¬" if comune_1=="MondovÃÆÃÂ¬"
(2 real changes made)

.         replace comune_1="MuggiÃ²" if comune_1=="MuggiÃÆÃÂ²"
(3 real changes made)

.         replace comune_1="NardÃ²" if comune_1=="NardÃÆÃÂ²"
(3 real changes made)

.         replace comune_1="San DonÃ  di Piave" if comune_1=="San Dona di Piave"
(5 real changes made)

.         replace comune_1="Sant’Angelo in Lizzola" if comune_1=="Sant'Angelo in Lizzola"
(1 real change made)

.         replace comune_1="ScorzÃ¨" if comune_1=="ScorzÃÆÃÂš"
(1 real change made)

.         replace comune_1="SeclÃ¬" if comune_1=="SeclÃÆÃÂ¬"
(1 real change made)

.         replace comune_1="Serra RiccÃ²" if comune_1=="Serra RiccÃÆÃÂ²"
(1 real change made)

.         replace comune_1="Vandoies/Vintl" if comune_1=="Vandoies"
(1 real change made)

. 
.         ** now we can merge it with the cleaned bridge file from ministry of interior:
.         merge m:1 comune_1 using "$data_original/comune info/handcoded_brigdefile_comuneIDs.dta", gen(_merge_comune)
(variable comune_1 was str36, now str62 to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         7,335
        from master                       350  (_merge_comune==1)
        from using                      6,985  (_merge_comune==2)

    Matched                             2,700  (_merge_comune==3)
    -----------------------------------------

.         fre _merge_comune

_merge_comune -- Matching result from merge
-----------------------------------------------------------------------
                          |      Freq.    Percent      Valid       Cum.
--------------------------+--------------------------------------------
Valid   1 Master only (1) |        350       3.49       3.49       3.49
        2 Using only (2)  |       6985      69.61      69.61      73.09
        3 Matched (3)     |       2700      26.91      26.91     100.00
        Total             |      10035     100.00     100.00           
-----------------------------------------------------------------------

.         drop if _merge_comune==2
(6,985 observations deleted)

. 
.         ** some cleanings of variables we do not need:
.         drop dup dup2 flags flagcodes value selezionaperiodo time statocivile statciv2 etã sesso sexistat1 tipodiindicatoredemogra
> fico tipo_dato15

. 
.         gen female_3=0

.         replace female_3=1 if s01==2 
(1,452 real changes made)

. 
.         gen age_3=2016-s03
(23 missing values generated)

. 
.         gen religious_3=0 if s09==7
(2,534 missing values generated)

.         replace religious_3=1 if s09!=7
(2,534 real changes made)

. 
.         gen edu_3=s10
(23 missing values generated)

.         label values edu_3 s10

.         recode edu_3 (7 8 9 = 6) (10 11 = 7)
(957 changes made to edu_3)

. 
.         gen unemployed_3=0

.         replace unemployed_3=1 if s11==2
(1,305 real changes made)

. 
.         gen vote13_2=S15
(1,788 missing values generated)

.         label values vote13_2 S15

. 
.         gen referendum_yes_3=0

.         replace referendum_yes_3=. if S27==2
(134 real changes made, 134 to missing)

.         replace referendum_yes_3=1 if S28==1 
(852 real changes made)

. 
.         gen referendum_no_3=0

.         replace referendum_no_3=. if S27==2
(134 real changes made, 134 to missing)

.         replace referendum_no_3=1 if S28==2 
(930 real changes made)

. 
.         gen referendum_yes_wunsure_3=0

.         replace referendum_yes_wunsure_3=. if S27==2
(134 real changes made, 134 to missing)

.         replace referendum_yes_wunsure_3=1 if S28==1
(852 real changes made)

.         replace referendum_yes_wunsure_3=1 if S29==1 
(61 real changes made)

.         
.         gen referendum_no_wunsure_3=0

.         replace referendum_no_wunsure_3=. if S27==2
(134 real changes made, 134 to missing)

.         replace referendum_no_wunsure_3=1 if S28==2 
(930 real changes made)

.         replace referendum_no_wunsure_3=1 if S29==2 
(85 real changes made)

.         
.         gen referendum_unsure_3=0

.         replace referendum_unsure_3=. if S27==2
(134 real changes made, 134 to missing)

.         replace referendum_unsure_3=1 if S28==3 | S27==3
(1,029 real changes made)

.         lab var referendum_unsure_3 "unsure in pre-wave"

. 
.         gen referendum_yes_4=0

.         replace referendum_yes_4=1 if D28_W9==2
(1,057 real changes made)

.         
.         gen referendum_no_4=0

.         replace referendum_no_4=1 if D28_W9==1
(1,659 real changes made)

.         
.         gen referendum_yes_wunsure_4=0

.         replace referendum_yes_wunsure_4=1 if D28_W9==2
(1,057 real changes made)

.         
.         gen referendum_no_wunsure_4=0

.         replace referendum_no_wunsure_4=1 if D28_W9==1
(1,659 real changes made)

.         
.         gen turnout_3=0

.         replace turnout_3=1 if S27==1
(2,386 real changes made)

.         
.         gen turnout_4=1

.         replace turnout_4=0 if D28_W9==4
(285 real changes made)

.         
.         gen eco_general_3=S18
(1 missing value generated)

.         replace eco_general_3=. if eco_general_3>=6
(29 real changes made, 29 to missing)

.         label values eco_general_3 S18

.         revrs eco_general_3, replace 

.         
.         gen eco_general_4=D1_W9

.         replace eco_general_4=. if eco_general_4>=6
(40 real changes made, 40 to missing)

.         label values eco_general_4 D1_W9

.         revrs eco_general_4, replace 

.         
.         ** We can use some of the pos-treatment variables as "manipulation tests": 
.         gen talk_politics_4=D16_W9

.         replace talk_politics_4=. if D16_W9>=6
(84 real changes made, 84 to missing)

.         label values talk_politics_4 D16_W9

.         
.         gen interest_ref_4=D17_W9

.         replace interest_ref_4=. if interest_ref_4==5
(49 real changes made, 49 to missing)

.         label values interest_ref_4 D17_W9

.         revrs interest_ref_4, replace 

.         
.         gen contact_tv_4=D18_01_W9

.         replace contact_tv_4=. if contact_tv_4>=5
(88 real changes made, 88 to missing)

.         label values contact_tv_4 D18_01_W9

.         revrs contact_tv_4, replace

.         
.         gen contact_paper_4=D18_03_W9

.         replace contact_paper_4=. if contact_paper_4>=5
(113 real changes made, 113 to missing)

.         label values contact_paper_4 D18_03_W9

.         revrs contact_paper_4, replace

.         
.         gen contact_radio_4=D18_05_W9

.         replace contact_radio_4=. if contact_radio_4>=5
(156 real changes made, 156 to missing)

.         label values contact_radio_4 D18_05_W9

.         revrs contact_radio_4, replace

.         
.         gen contact_personal_4=D18_02_W9

.         replace contact_personal_4=. if contact_personal_4>=5
(118 real changes made, 118 to missing)

.         label values contact_personal_4 D18_02_W9

.         revrs contact_personal_4, replace

.         
.         gen contact_politican_4=D18_06_W9

.         replace contact_politican_4=. if contact_politican_4>=5
(173 real changes made, 173 to missing)

.         label values contact_politican_4 D18_06_W9

.         revrs contact_politican_4, replace 

.         
.         gen contact_web_4=D18_07_W9

.         replace contact_web_4=. if contact_web_4>=5
(105 real changes made, 105 to missing)

.         label values contact_web_4 D18_07_W9

.         revrs contact_web_4, replace 

.         
.         gen web_politican_4=D21_01_W9

.         replace web_politican_4=. if web_politican_4>=5
(104 real changes made, 104 to missing)

.         label values web_politican_4 D21_01_W9

.         revrs web_politican_4, replace 

.         
.         gen web_socmedia_4=D21_02_W9

.         replace web_socmedia_4=. if web_socmedia_4>=5
(95 real changes made, 95 to missing)

.         label values web_socmedia_4 D21_02_W9

.         revrs web_socmedia_4, replace 

.         
.         gen web_video_4=D21_03_W9

.         replace web_video_4=. if web_video_4>=5
(97 real changes made, 97 to missing)

.         label values web_video_4 D21_03_W9

.         revrs web_video_4, replace 

.         
.         gen web_share_4=D21_04_W9

.         replace web_share_4=. if web_share_4>=5
(94 real changes made, 94 to missing)

.         label values web_share_4 D21_04_W9

.         revrs web_share_4, replace 

.         
.         gen web_discuss_4=D21_05_W9

.         replace web_discuss_4=. if web_discuss_4>=5
(105 real changes made, 105 to missing)

.         label values web_discuss_4 D21_05_W9

.         revrs web_discuss_4, replace 

.         
.         gen web_event_4=D21_06_W9

.         replace web_event_4=. if web_event_4>=5
(109 real changes made, 109 to missing)

.         label values web_event_4 D21_06_W9

.         revrs web_event_4, replace 

.         
.         ** Now we can reshape the data from wide to long: 
.         gen id=_n

.         gen date=SERIE

. 
.         ** keep ID region-date
.         order id ID date

. 
.         ** ok some do not have IDs (new ones) but we want to keep them, so we assign them a non existent ID:
.         replace ID=999999999+id if ID==.
(23 real changes made)

. 
.         merge 1:1 ID using "`13itans'"

    Result                      Number of obs
    -----------------------------------------
    Not matched                         6,319
        from master                       323  (_merge==1)
        from using                      5,996  (_merge==2)

    Matched                             2,727  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(5,996 observations deleted)

.         drop _merge

. 
.         reshape long ///
>         vote08_ idate_ talk_politics_ ///
>         turnout_ referendum_yes_ referendum_yes_wunsure_ referendum_no_ referendum_no_wunsure_ ///
>         eco_general_ reform_general_ ///
>         , i(id) j(wave)  
(j = 1 3 4)
(variable vote08_1 not found)
(variable idate_1 not found)
(variable turnout_1 not found)
(variable referendum_yes_1 not found)
(variable referendum_yes_wunsure_1 not found)
(variable referendum_no_1 not found)
(variable referendum_no_wunsure_1 not found)
(variable reform_general_1 not found)
(variable vote08_3 not found)
(variable idate_3 not found)
(variable talk_politics_3 not found)
(variable reform_general_3 not found)
(variable vote08_4 not found)
(variable idate_4 not found)
(variable reform_general_4 not found)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations            3,050   ->   9,150       
Number of variables                 186   ->   182         
j variable (3 values)                     ->   wave
xij variables:
             vote08_1 vote08_3 vote08_4   ->   vote08_
                idate_1 idate_3 idate_4   ->   idate_
talk_politics_1 talk_politics_3 talk_politics_4->talk_politics_
          turnout_1 turnout_3 turnout_4   ->   turnout_
referendum_yes_1 referendum_yes_3 referendum_yes_4->referendum_yes_
referendum_yes_wunsure_1 referendum_yes_wunsure_3 referendum_yes_wunsure_4->referendum_yes_wunsure_
referendum_no_1 referendum_no_3 referendum_no_4->referendum_no_
referendum_no_wunsure_1 referendum_no_wunsure_3 referendum_no_wunsure_4->referendum_no_wunsure_
eco_general_1 eco_general_3 eco_general_4 ->   eco_general_
reform_general_1 reform_general_3 reform_general_4->reform_general_
-----------------------------------------------------------------------------

. 
.         ** correct some labels: 
.         foreach var of varlist *_ {
  2.                 local newname = regexr("`var'","_$","") 
  3.                 rename `var' `newname'
  4.         }

. 
.         ** post variables should be missing other than post wave:
.         foreach var of varlist *_4 {
  2.                 replace `var'=. if wave!=4
  3.         }
(6,098 real changes made, 6,098 to missing)
(6,098 real changes made, 6,098 to missing)
(6,098 real changes made, 6,098 to missing)
(6,002 real changes made, 6,002 to missing)
(5,924 real changes made, 5,924 to missing)
(5,874 real changes made, 5,874 to missing)
(5,788 real changes made, 5,788 to missing)
(5,864 real changes made, 5,864 to missing)
(5,754 real changes made, 5,754 to missing)
(5,890 real changes made, 5,890 to missing)
(5,892 real changes made, 5,892 to missing)
(5,910 real changes made, 5,910 to missing)
(5,906 real changes made, 5,906 to missing)
(5,912 real changes made, 5,912 to missing)
(5,890 real changes made, 5,890 to missing)
(5,882 real changes made, 5,882 to missing)

. 
.         ** take care of labels:
.         label values vote08 Q151

.         label values idate DATA

.         label values talk_politics Q021

.         label values vote13_1 Q150

.         
. 
.         xtset id wave

Panel variable: id (strongly balanced)
 Time variable: wave, 1 to 4, but with gaps
         Delta: 1 unit

. 
.         order *_1 *_4 

.         order id ID wave date idate region_1 province_1 comune_1 comune_id_1

. 
.         save "$data_coded/placebased_individual.dta", replace 
file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_individual.dta saved

. 
. 
. 
. 
. *
.         // now we can measure the panel data again with our M5S infos: 
. 
.         ** Here we open the m5s meetup data, do some cleanings:
.         project, original("$data_coded/events_comune_neigh_nga.csv")
project PlaceBased_analysis > do-file uses original: "data_coded/events_comune_neigh_nga.csv" filesig(2414589165:3213673)

.         import delimited "$data_coded/events_comune_neigh_nga.csv", clear 
(177 vars, 7,998 obs)

. 
.         *import meetup data, clear and save temporary
.         foreach w of varlist n_* wn_* hist_* {
  2.                 replace `w'=0 if `w'==.
  3.                 *destring `w', replace /* thomas, dec 3: NAs in csv now formatted stata style --> is already numeric, na==. */
.         }
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)

.         
.         *we standardize the exposure variable as discussed in the paper on p.XXX
.         foreach var of varlist n_total-hist_wn_late {
  2.                 gen std_`var'=log((`var'/log(comune_population))+1)
  3.         }

.         
.         tempfile meetup

.         save `meetup'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000006 saved as .dta format

. 
. 
. 
. 
. *
.         // import panel data and merge with M5S infos:
.         use "$data_coded/placebased_individual.dta", clear

.         
.         rename ïitter107 comune_id

.         destring comune_id, replace
comune_id: all characters numeric; replaced as long
(1050 missing values generated)

.         
.         merge m:1 comune_id using "`meetup'", gen(_merge_meetup)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         8,007
        from master                     1,053  (_merge_meetup==1)
        from using                      6,954  (_merge_meetup==2)

    Matched                             8,097  (_merge_meetup==3)
    -----------------------------------------

.         drop if _merge_meetup==2
(6,954 observations deleted)

.                 
. *
.         // cleanings/codings: 
. 
.         replace comune_id_1=. if comune_id_1==1 
(1,041 real changes made, 1,041 to missing)

.         *
.         gen m5s_no=0

.         replace m5s_no=1 if n_total==0
(2,958 real changes made)

.         replace m5s_no=. if n_total==.
(1,053 real changes made, 1,053 to missing)

.         *
.         gen ever_treated=0

.         replace ever_treated=1 if n_total>=1
(6,192 real changes made)

.         replace ever_treated=. if n_total==.
(1,053 real changes made, 1,053 to missing)

.         *
.         gen referendum=0 if wave==3
(6,100 missing values generated)

.         replace referendum=1 if wave==4
(3,050 real changes made)

.         *
.         gen no_comune=0

.         replace no_comune=1 if comune_id_1==1 | comune_id_1==.
(1,041 real changes made)

.         *
.         gen m5s_1=0

.         replace m5s_1=1 if vote13_1==4
(1,419 real changes made)

.         replace m5s_1=. if vote13_1==.
(2,691 real changes made, 2,691 to missing)

.         *
.         gen pd_1=0

.         replace pd_1=1 if vote13_1==2
(1,767 real changes made)

.         replace pd_1=. if vote13_1==.
(2,691 real changes made, 2,691 to missing)

.         *
.         gen pdl_1=0

.         replace pdl_1=1 if vote13_1==1
(996 real changes made)

.         replace pdl_1=. if vote13_1==.
(2,691 real changes made, 2,691 to missing)

.         *
.         gen vote_main_1=0

.         replace vote_main_1=1 if vote13_1==2 
(1,767 real changes made)

.         replace vote_main_1=2 if vote13_1==4 
(1,419 real changes made)

.         replace vote_main_1=3 if vote13_1==1 
(996 real changes made)

.         replace vote_main_1=4 if vote13_1==5
(543 real changes made)

.         replace vote_main_1=. if vote13_1==. 
(2,691 real changes made, 2,691 to missing)

.         label define main_vote 1 "PD" 2 "M5S" 3 "PDL" 4 "Monti"  0 "other"

.         label values vote_main_1 main_vote

.         *
.         gen h1=0

.         replace h1=1 if reform_general==6 & wave==3
(0 real changes made)

.         replace h1=. if reform_general==. & wave==3
(3,050 real changes made, 3,050 to missing)

.         bysort id: egen undecided=max(h1)

.         drop h1

.         *
.         gen h1=reform_general if wave==3
(9,150 missing values generated)

.         bysort id: egen reform_general_3=max(h1)
(9,150 missing values generated)

.         drop h1

. 
.         *different treatments across time: 
.         
.         gen wave_n_treat_157=n_pre_157d if wave==3 
(6,451 missing values generated)

.         replace wave_n_treat_157=n_treat_157d if wave==4
(2,699 real changes made)

.         
.         gen wave_wn_treat_157d=wn_pre_157d if wave==3 
(6,451 missing values generated)

.         replace wave_wn_treat_157d=wn_treat_157d if wave==4 
(2,699 real changes made)

.         
.         gen wave_neigh_wn_treat_157d=wn_neigh_pre_157d if wave==3 
(6,451 missing values generated)

.         replace wave_neigh_wn_treat_157d=wn_neigh_treat_157d if wave==4 
(2,699 real changes made)

.         
.         gen wave_n_treat_120=n_pre_120d if wave==3 
(6,451 missing values generated)

.         replace wave_n_treat_120=n_treat_120d if wave==4
(2,699 real changes made)

.         
.         gen wave_n_treat_90=n_pre_90d if wave==3 
(6,451 missing values generated)

.         replace wave_n_treat_90=n_treat_90d if wave==4
(2,699 real changes made)

.         
.         gen wave_n_treat_60=n_pre_60d if wave==3 
(6,451 missing values generated)

.         replace wave_n_treat_60=n_treat_60d if wave==4
(2,699 real changes made)

.         
.         gen wave_n_treat_30=n_pre_30d if wave==3 
(6,451 missing values generated)

.         replace wave_n_treat_30=n_treat_30d if wave==4
(2,699 real changes made)

.         
.         gen wave_wn_treat_157d_in=wn_pre_loc_indoor_157d if wave==3 
(6,451 missing values generated)

.         replace wave_wn_treat_157d_in=wn_treat_loc_indoor_157d if wave==4 
(2,699 real changes made)

.         
.         gen wave_wn_treat_157d_out=wn_pre_loc_outdoor_157d if wave==3 
(6,451 missing values generated)

.         replace wave_wn_treat_157d_out=wn_treat_loc_outdoor_157d if wave==4 
(2,699 real changes made)

.         
.         ** to standardize exposure as discussed in paper we need to merge with regional level data: 
.         drop _merge*

.         merge m:1 comune_id using "$data_coded/placebased_regional.dta", force
(note: variable first_event was float in the using data, but will be str10 now)
(variable comune_id was long, now double to accommodate using data's values)
(variable province_id was int, now long to accommodate using data's values)
(variable region_id was byte, now long to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         8,007
        from master                     1,053  (_merge==1)
        from using                      6,954  (_merge==2)

    Matched                             8,097  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(6,954 observations deleted)

.         drop _merge

. 
.         *standardize M5S infos by pop:
.         foreach var of varlist wave_n_treat_157-wave_wn_treat_157d_out {
  2.         gen std_`var'=log((`var'/exposure_pop)+1)
  3.         }
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)
(3,752 missing values generated)

. 
.         * some cleanings of identifiers:
.         drop province_id region_id 

.         gen province_id=province_1
(72 missing values generated)

.         gen region_id=region_1
(69 missing values generated)

.         
.         *
.         xtset

Panel variable: id (strongly balanced)
 Time variable: wave, 1 to 4, but with gaps
         Delta: 1 unit

.         gen lturnout=l.turnout
(6,100 missing values generated)

.         
.         gen turnout_noyes=0 if lturnout==0 
(8,486 missing values generated)

.         replace turnout_noyes=1 if (turnout==1 & wave==4) & lturnout==0
(490 real changes made)

.         
.         gen post=0 if wave==3
(6,100 missing values generated)

.         replace post=1 if wave==4
(3,050 real changes made)

.         
.         rename n_total m5s_total

.         
.         rename std_wave_wn_treat_157d m5s_wn_wave_157

.         lab var m5s_wn_wave_157 "M5S: campaign"

.         
.         rename std_wave_n_treat_157 m5s_n_wave_157

.         lab var m5s_n_wave_157 "M5S: campaign"

.         
.         lab var m5s_no "M5S: never exposed"

.         
.         *
.         gen m5s_ref_yn=0

.         replace m5s_ref_yn=1 if m5s_n_wave_157>0
(6,702 real changes made)

.         replace m5s_ref_yn=. if m5s_n_wave_157==.
(3,752 real changes made, 3,752 to missing)

.         *
.         bysort comune_id: egen h1=max(m5s_n_wave_157)
(1,053 missing values generated)

.         drop m5s_ref_ever

.         gen m5s_ref_ever=0

.         replace m5s_ref_ever=1 if h1>0
(5,796 real changes made)

.         replace m5s_ref_ever=. if m5s_n_wave_157==.
(3,752 real changes made, 3,752 to missing)

.         drop h1 

.         
.         *
.         gen m5s_ref_neig_yn=0

.         replace m5s_ref_neig_yn=1 if std_wave_neigh_wn_treat_157d>0
(7,291 real changes made)

.         replace m5s_ref_neig_yn=. if std_wave_neigh_wn_treat_157d==.
(3,752 real changes made, 3,752 to missing)

.         *
.         bysort comune_id: egen h1=max(std_wave_neigh_wn_treat_157d)
(1,053 missing values generated)

.         gen m5s_ref_neigh_ever=0

.         replace m5s_ref_neigh_ever=1 if h1>0
(6,525 real changes made)

.         replace m5s_ref_neigh_ever=. if std_wave_neigh_wn_treat_157d==.
(3,752 real changes made, 3,752 to missing)

.         drop h1 

.         
.         
.         merge m:1 ID using "`13_pre'", force
(note: variable SERIE was long in the using data, but will be str10 now)
(label Q021 already defined)
(label Q150 already defined)
(label revpolinterest_1 already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                         6,965
        from master                       969  (_merge==1)
        from using                      5,996  (_merge==2)

    Matched                             8,181  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(5,996 observations deleted)

.         drop _merge

.         
.         lab var unemployed_3 "unemployed (0,1)"

.         lab var unemployed_1 "unemployed (0,1)"

.         lab var female_3 "female (0,1)"

.         lab var female_1 "female (0,1)"

.         lab var age_3 "age (18-88)"

.         lab var age_1 "age (18-89)"

.         lab var edu_3 "education (1-7)"

.         lab var edu_1 "education (1-7)"

.         lab var religious_3 "religiosity (      0,1)"

.         lab var std_wave_n_treat_90 "M5S: 3 months before referendum"

.         lab var std_wave_n_treat_60 "M5S: 2 months before referendum"

.         lab var std_wave_n_treat_30 "M5S: 1 month before referendum"

.         lab var polinterest_1 "political interest (1-4)"

.         lab var m5s_1 "M5S voter in 2013 (0,1)"

.         lab var pd_1 "PD voter in 2013 (0,1)"

.         lab var pdl_1 "PdL voter in 2013 (0,1)"

.         lab var lr_1 "left-right (1-10)"

.         lab var m5s_n_wave_157 "M5S: referendum {it:(events only)}"

.         lab var m5s_wn_wave_157 "M5S: referendum"

.         lab var m5s_ref_yn "M5S: binary"

.         lab var eco_general_1 "economy retrospective (1-5)"

.         lab var lr_no_1 "explicitly no lr placement (0,1)"

.         lab var talk_politics_1 "talk politics (1-6)"

.         lab var pol_complex_1 "politics too complex (1-4)"

.         lab var internal_efficacy_1 "internal efficacy (1-4)"

.         lab var referendum_no "vote no (0,1)"

.         lab var referendum_no_wunsure "vote no (0,1)"

.         lab var referendum_yes "vote yes (0,1)"

.         lab var referendum_yes_wunsure "vote yes (0,1)"

.         lab var std_wave_wn_treat_157d_in "M5S indoor"

.         lab var std_wave_wn_treat_157d_out "M5S outdoor"

.         
.         *mean imputation: 
.         foreach var of varlist age_3 edu_3 {
  2.                 egen `var'_mean=mean(`var')
  3.                 gen `var'_imp=`var'
  4.                 replace `var'_imp=`var'_mean if `var'_imp==.
  5.         }
(69 missing values generated)
(69 real changes made)
(69 missing values generated)
(69 real changes made)

.         
.         save "$data_coded/placebased_individual.dta", replace 
file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_individual.dta saved

. 
.         *codebookout "$data_coded/codebookplacebased_individual"
. 
.         project, creates("$data_coded/placebased_individual.dta")
project PlaceBased_analysis > do-file creates: "data_coded/placebased_individual.dta" filesig(836765086:58113503)

. 
end of do-file
      name:  plog_12
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/06_prepare_individual.log
  log type:  text
 closed on:  19 Sep 2022, 11:38:51
------------------------------------------------------------------------------------------------------------------------------------
